@extends('home.lei.business.index')
@section('r_content')
	<link rel="stylesheet" href="/lei/home/shenqing.css">
	<div style="width:950px;height:100%;float:left;background:white;margin-left:10px;">
		<form class="navbar-form navbar-left" role="search" action="/home/store/{{$data['id']}}" id="art_form" method="post"  enctype="multipart/form-data">
				{{csrf_field()}}	
				<input type="hidden" name="_method" value="PUT">
				  <div class="form-group">
				    	<b class="icon">*</b></label><span>商铺名称：</span><input readonly type="text" id="b_name" name="b_name" value="{{$data['b_name']}}" class="form-control" style="width:300px">
				  </div><br>
				  <div class="form-group" id="b_ph"> 
				    	<b class="icon">*</b></label><span>店铺电话：</span><input type="text" id="b_phone" name="b_phone" value="{{$data['b_phone']}}" class="form-control"><span></span>
				  </div><br>
				  <div class="form-group" id="b_add">
				    	<b class="icon">*</b></label><span>商铺地址：</span><input type="text" id="b_address" name="b_address" value="{{$data['b_address']}}" class="form-control" style="width:350px;"><span></span>
				  </div><br>
				  <div class="form-group" id="b_des">
				    	<b class="icon">*</b></label><span>商铺描述：</span><input type="text" id="b_description" name="b_description" value="{{$data['b_description']}}" class="form-control" style="width:400px;"><span></span>
				  </div><br>
				  <div class="form-group" id="time">
				    	<b class="icon">*</b></label><span>营业时间：</span><input type="time" id="startime" name="startime" value="{{explode('~~',$data['b_workTime'])[0]}}" class="form-control" style="width:100px;"><span>~~</span><input type="time" id="endTime" name="endtime" value="{{explode('~~',$data['b_workTime'])[1]}}" class="form-control" style="width:100px;"><span></span>
				  </div><br>
				  <div class="form-group" id="b_up">
				    	<b class="icon">*</b></label><span>起送价格：</span><input type="text" id="b_upPrice" name="b_upPrice" value="{{$data['b_upPrice']}}" class="form-control" style="width:100px;"><span>元</span><span></span>
				  </div><br>
				  <div class="form-group" id="b_dis">
				    	<b class="icon">*</b></label><span>配送费用：</span><input type="text" id="b_distribution" name="b_distribution" value="{{$data['b_distribution']}}" class="form-control" style="width:100px;"><span>元</span><span></span>
				  </div><br>
				  <div class="form-group">
				  		<div style="float:left;"><b class="icon">*</b></label><span>商铺logo：</span></div>
				    	<div style="border:1px solid #ccc;width:800px;height:160px;float:left;">
				    		<div style="width:228px;float:left;">
				    			示例规格:228*137:<img src="/lei/images/default.jpg" style="height:137px;" alt="">
				    		</div>
				    		<div style="float:left;margin-top:50px;margin-left:10px;">
				    			<input type="hidden" name="permit" id="permit" value="">
				    			<input id="file_permit" name="file_permit" type="file" multiple="true">
				    		</div>
				    		<div>
								<img id="img2" src="" style="width:228px;height:137px;margin-top:10px;" alt="">
							</div>
				    	</div>
				  </div><br>
				  <div class="form-group">
				    	<input style="width:100px;height:40px;margin-left:200px;" type="submit" value="修改">
				    	<input style="width:100px;height:40px;margin-left:200px;" type="reset" value="重置">
				  </div><br>
			</form>
	</div>
	<script>
		 $('#b_phone').blur(function(){
		 	var phone = $('#b_phone').val();
			if(!(/^1(3|4|5|7|8)\d{9}$/.test(phone))){ 
		        $('#b_ph span').eq(1).html('<span style="font-size:10px;color:red;">✘手机号码有误，请重新填写</span>');
		    }else{
		    	$('#b_ph span').eq(1).html('<span style="color:green;font-size:20px;">✔</span>');
		    } 
		 });
		 $('#b_address').blur(function(){
			var add = $('#b_address').val();
			if(!$('#b_address').val()){
				$('#b_add span').eq(1).html('<span style="font-size:10px;color:red;">✘地址不能为空</span>');
			}else{
				$('#b_add span').eq(1).html('<span style="color:green;font-size:20px;">✔</span>');
			}
		});
		 $('#b_description').blur(function(){
			var add = $('#b_description').val();
			if(!$('#b_description').val()){
				$('#b_des span').eq(1).html('<span style="font-size:10px;color:red;">✘描述不能为空</span>');
			}else{
				$('#b_des span').eq(1).html('<span style="color:green;font-size:20px;">✔</span>');
			}
		});
		 $('#startime').blur(function(){
			if(!$('#startime').val()){
				$('#time span').eq(2).html('<span style="font-size:10px;color:red;">✘时间不能为空</span>');
			}else{
				$('#time span').eq(2).html('<span style="color:green;font-size:20px;">✔</span>');
			}
		});
		$('#endtime').blur(function(){
			if(!$('#endtime').val()){
				$('#time span').eq(2).html('<span style="font-size:10px;color:red;">✘时间不能为空</span>');
			}else{
				$('#time span').eq(2).html('<span style="color:green;font-size:20px;">✔</span>');
			}
		});
		$('#b_upPrice').blur(function(){
		 	var phone = $('#b_upPrice').val();
			if(!(/^(1|2|3|4|5|6|7|8|9)\d{1,}$/.test(phone))){ 
		        $('#b_up span').eq(1).html('<span style="font-size:10px;color:red;">✘起送价格有误</span>');
		    }else{
		    	$('#b_up span').eq(1).html('<span style="color:green;font-size:20px;">✔</span>');
		    } 
		 });
		$('#b_distribution').blur(function(){
		 	var phone = $('#b_distribution').val();
			if(!(/^(1|2|3|4|5|6|7|8|9)\d{1,}$/.test(phone))){ 
		        $('#b_dis span').eq(1).html('<span style="font-size:10px;color:red;">✘配送费用有误</span>');
		    }else{
		    	$('#b_dis span').eq(1).html('<span style="color:green;font-size:20px;">✔</span>');
		    } 
		 });
		$(function () {
            $("#file_permit").change(function () {
                uploadImages();
            });
        });

        //上传图片
        function uploadImages() {
		//判断是否有选择上传文件
            var imgPath = $("#file_permit").val();
            if (imgPath == "") {
                alert("请选择上传图片！");
                return;
            }
            //判断上传文件的后缀名
            var strExtension = imgPath.substr(imgPath.lastIndexOf('.') + 1).toLowerCase();
            if (strExtension != 'jpg' && strExtension != 'gif'
                && strExtension != 'png' && strExtension != 'bmp') {
                alert("请选择图片文件");
                return;
            }
            var formData = new FormData();
            formData.append("file_permit", $('#file_permit')[0].files[0]);
            formData.append("_token", '{{csrf_token()}}');
            $.ajax({
                type: "post",
                url: "/upload/logo",
                data: formData,
                async: true,
                cache: false,
                contentType: false,
                processData: false,
                success: function(data) {
                    $('#img2').attr('src','/'+data);
                    $('#permit').val(data);

                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert("上传失败，请检查网络后重试");
                }
            });
        }
	</script>
@endsection